﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using GestionEco;

namespace Ecosystème
{
    class Serialiser
    {
        XmlSerializer xs;
        String cheminXMLsave = "C:\\Users\\adrien\\Desktop\\saveEspeces.xml";

        public void serialiserAnimal(Animal animal)
        {
            StreamWriter writer = new StreamWriter(cheminXMLsave);
            xs = new XmlSerializer(typeof(Animal));

            xs.Serialize(writer, animal);

            writer.Close();
        }

        public void serialiserVegetal(Vegetal vegetal)
        {
            StreamWriter writer = new StreamWriter(cheminXMLsave);
            xs = new XmlSerializer(typeof(Vegetal));

            xs.Serialize(writer, vegetal);

            writer.Close();
        }

        public Animal deserialiserAnimal()
        {
            StreamReader reader = new StreamReader(cheminXMLsave);

            Animal c = (Animal)xs.Deserialize(reader);

            reader.Close();
            return c;
        }

        public Vegetal deserialiserVegetal()
        {
            StreamReader reader = new StreamReader(cheminXMLsave);

            Vegetal c = (Vegetal)xs.Deserialize(reader);

            reader.Close();
            return c;
        }
    }
}
